<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="model.*" %>
<%@ taglib prefix="s" uri="/struts-tags" %>   
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'importTeacher.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	<link rel="stylesheet" type="text/css" href="css/common.css">
	
<script src="js/prototype.js" type="text/javascript">  
</script>  
<script language="JavaScript">  
    function gotClick()   
    {   
        //请求的地址   
        var url = 'departmentspecial.action';   
        //将form1表单域的值转换为请求参数   
        var params ="specialdepartmentId="+document.getElementById("specialdepartmentId").value;
        //创建Ajax.Request对象，对应于发送请求   
        var myAjax = new Ajax.Request(   
        url,   
        {   
            //请求方式：POST   
            method:'post',   
            //请求参数   
            parameters:params,   
            //指定回调函数   
            onComplete: processResponse,   
            //是否异步发送请求   
            asynchronous:true   
        });   
    }   
    function processResponse(request)   
    {   
    	//document.getElementById("show").innerHTML=request.responseText;
        var data = eval('('+request.responseText+')'); 
        document.getElementById("stuspecialId").options.length=0;
        var option=new Option("全部","0");
        document.getElementById("stuspecialId").options.add(option); 
        for(var i=0;i<data.departmentspecials.length;i++)
        {
        	var option=new Option(data.departmentspecials[i].specialname,data.departmentspecials[i].id);
        	document.getElementById("stuspecialId").options.add(option); 
        }  
    }      
</script> 
  </head>
  
  <body>
  <div id="main">
  <fieldset>
  	<legend>
  		查询学生信息
  	</legend>
  		<form name="searchform" action="searchstudents.action" method="post">
  			<input type="hidden" name="currentpage" id="currentpage" value="${currentpage }"/>
  			<input type="hidden" name="pageresult" id="pageresult" value="${pageresult }"/>
  			<input type="hidden" name="pagecount" id="pagecount" value="${pagecount }"/>
  			<input type="hidden" name="resultcount" id="resultcount" value="${resultcount }"/>
  			<input type="hidden" name="actiontype" id="actiontype" value="${actiontype }"/>
  			<input type="hidden" name="actionname" id="actionname" value="${actionname }"/>
	  		<table>
	  			<tr>
	  				<td class="searchTd">学号</td><td class="searchTd"><input type="text" name="stunumber" id="stunumber" value="${stunumber}"/></td>
	  				<td class="searchTd">姓名</td><td class="searchTd"><input type="text" name="stuname" id="stuname" value="${stuname}"/></td>
	  				<td class="searchTd">性别</td>
	  				<td class="searchTd">
	  				<%
	  					String stusex=(String)ActionContext.getContext().getValueStack().findValue("stusex");
	  					if(stusex==null)
	  						stusex="0";
	  				 %>
		  				<select name="stusex" id="stusex">
		  					<option value="0">全部</option>
		  					<option value="男" <%if(stusex.equals("男")) out.print("selected='selected'"); %>>男</option>
		  					<option value="女" <%if(stusex.equals("女")) out.print("selected='selected'"); %>>女</option>
		  				</select>
	  				<%
	  					String specialdepartmentIdstring=(String)ActionContext.getContext().getValueStack().findValue("specialdepartmentId");
	  					String stuspecialIdstring=(String)ActionContext.getContext().getValueStack().findValue("stuspecialId");
	  					int specialdepartmentId=0;
	  					int stuspecialId=0;
	  					if(specialdepartmentIdstring!=null)
	  						 specialdepartmentId= Integer.parseInt(specialdepartmentIdstring);
	  					if(stuspecialIdstring!=null)
	  						 stuspecialId= Integer.parseInt(stuspecialIdstring);
	  					List totaldepartments=(List)request.getAttribute("totaldepartments");
	  				 %>
	  				 </td>
	  			</tr>
	  			<tr>
	  				 <td class="searchTd">学院</td>
	  				 <td class="searchTd">
		  				<select name="specialdepartmentId" id="specialdepartmentId" onchange="javascript:gotClick();">
		  					<option value="0">全部</option>
		  					<%
		  					for(int i=0;i<totaldepartments.size();i++)
		  					{
		  					Department d = new Department();
		  					d = (Department)totaldepartments.get(i);
		  					 %>
		  					 <option value="<%=d.getId() %>" <%if(d.getId()==specialdepartmentId) out.print("selected='selected'"); %>><%=d.getDepartmentname() %></option>
		  					 <%
		  					 }
		  					  %>
		  				</select>
	  				</td>
	  				<script type="text/javascript">
	  					document.getElementById("specialdepartmentId").onchange();//初始化专业列表
	  				</script>
	  				<td class="searchTd">专业</td>
	  				<td class="searchTd">
	  					<select name="stuspecialId" id="stuspecialId">
	  						
	  					</select>
	  				</td>
	  				<td class="searchTd"><input type="submit" value="搜索" class="button" onclick="qingkong()"/></td>
	  			</tr>
	  		</table>
	  	</form>
  </fieldset>
  <fieldset>
  	<legend>
  		学生信息
  	</legend>
  	
  	<table>
  		<tr>
  			<td colspan="8"><font color=""><a href="admin/info/importStudent.jsp">导入</a></font></td>
  		</tr>
  		<tr class="trTitle">
  			<td>学号</td><td>姓名</td><td>性别</td><td>邮箱</td><td>联系方式</td><td>家庭住址</td><td>专业</td><td>学院</td>
  		</tr>
  		<%
  		int i=1;
  		 %>
	   	<s:iterator value="students" status="student"> 
	   	<tr <%if(i%2==0) out.print("class='trstyle1'"); else out.print("class='trstyle2'");%>>
			<td><s:property id="student" value="stunumber" /></td>
			<td><a href="getstudentbyid.action?id=<s:property id="student" value="id" />"><s:property id="student" value="stuname" /></a></td>
			<td><s:property id="student" value="stusex" /></td>
			<td><s:property id="student" value="stuemail" /></td>
			<td><s:property id="student" value="stutelephone" /></td>
			<td><s:property id="student" value="stuaddress" /></td>
			<td>
				<s:iterator value="specials[#student.index]" status="special">
					<s:property id="special" value="specialname" />
				</s:iterator>
			</td>
			<td>
				<s:iterator value="departments[#student.index]" status="department">
					<s:property id="department" value="departmentname" />
				</s:iterator>
			</td>
		</tr>
		<%
		i++;
		 %>
		</s:iterator> 
	</table>
		<%@include file="/util/page.jsp"%>
  </fieldset>
  </div>
 
  </body>
</html>